//@author A0101032L

#include "UI.h"

void UI::UI_interface(){
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	string command;
	bool statusFlag = false;

	displayWelcomeMessage(hConsole);
	
	while (!statusFlag) {
		displayCommandMessage(command, hConsole);
		displayProcessorMessage(command, hConsole, statusFlag);
	}
}


void UI::displayWelcomeMessage(HANDLE hConsole){
	SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	cout << MESSAGE_WELCOME << endl<<endl;
	 
	string message;

	 SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
	 _logic.execute(COMMAND_DISPLAY_TASK_TODAY, &message);
	 
	 if (message != "") {
		cout << MESSAGE_TASKS_TODAY;
	 } else {
		 cout << MESSAGE_NO_TASKS_TODAY;
	 }
	 vector<string> feedback;
	cout << message << endl;
}
 

void UI::displayCommandMessage(string& command, HANDLE hConsole){
	SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	cout <<MESSAGE_COMMAND;
	getline(cin, command);
	while(command==""){
		SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
		cout<<MESSAGE_ERROR_EMPTY_INPUT<<endl;
		cout<<COMMAND_HELP<<endl;

		SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_INTENSITY);
		cout<<MESSAGE_COMMAND; 
		getline(cin, command);
	}

}


void UI::displayProcessorMessage(string command, HANDLE hConsole, bool& statusFlag){
	string message;
	message.clear();
	

	int output = _logic.execute(command, &message); 
	

	if( (output >= STATUS_CODE_SET_ERROR:: ERROR_ADD) && ( output <= STATUS_CODE_SET_ERROR:: ERROR_RELOCATE))
	{
		error(output, hConsole);
	}

	else if( (output>= STATUS_CODE_SET_SUCCESS:: SUCCESS_ADD) && (output<= STATUS_CODE_SET_SUCCESS::SUCCESS_CLEAR))
	{
		success(output, hConsole);
	}

	else if( (output>= STATUS_CODE_SET_WARNING::WARNING_DISPLAY_NO_RESULT) && (output<= STATUS_CODE_SET_WARNING:: WARNING_RENAME_CLASH))
	{
		warning(output, hConsole);
	}
	
	else if (output == STATUS_CODE_SET_OVERALL::OVERALL_EXIT)
	{
	statusFlag = true;	
	}

	SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	
	if(!message.empty()) {
	SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	cout << endl << message << endl;
	}

	SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	
	
	cout << endl;
	if(statusFlag==true){
		
		SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
		cout<<MESSAGE_GOODBYE<<endl;
		_logic.execute(COMMAND_DISPLAY_TASK_TODAY, &message);
		cout<<message<<endl;
		system("pause");
		
	}

}

void UI::error(int code, HANDLE hConsole){

	SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);

	switch(code){


	case STATUS_CODE_SET_ERROR:: ERROR_ADD:
		cout<<MESSAGE_ERROR_ADD<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR::ERROR_ADD_DUPLICATE:
		cout<<MESSAGE_ERROR_ADD_DUPLICATE<< endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_REMOVE:
		cout<<MESSAGE_ERROR_REMOVE<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_DISPLAY:
		cout<<MESSAGE_ERROR_DISPLAY<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_MARK:
		cout<<MESSAGE_ERROR_MARK<< endl;
		//cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_UNMARK:
		cout<<MESSAGE_ERROR_UNMARK<< endl;
		//cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_SEARCH:
		cout<<MESSAGE_ERROR_SEARCH<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_UNDO:
		cout<<MESSAGE_ERROR_UNDO<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_REDO:
		cout<<MESSAGE_ERROR_REDO<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_CLEAR:
		cout<<MESSAGE_ERROR_CLEAR<< endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_EMPTY_INPUT:
		cout<<MESSAGE_ERROR_EMPTY_INPUT<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_INTERPRETER_FORMAT:
		cout<<MESSAGE_ERROR_INTERPRETER_FORMAT<< endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_INTERPRETER_DATETIME_FORMAT:
		cout<<MESSAGE_ERROR_INTERPRETER_DATETIME_FORMAT<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_INTERPRETER_PARAMETER_OVERLOAD_TIME:
		cout<<MESSAGE_ERROR_INTERPRETER_PARAMETER_OVERLOAD_TIME<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR::ERROR_INTERPRETER_START_TIME_BUT_NO_END_TIME:
		cout<<MESSAGE_ERROR_INTERPRETER_START_TIME_BUT_NO_END_TIME<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_ENDTIME_BEFORE_STARTTIME:
		cout<<MESSAGE_ERROR_INTERPRETER_ENDTIME_BEFORE_STARTTIME<< endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_INTERPRETER_DATETIME_INVALID:
		cout<<MESSAGE_ERROR_INTERPRETER_DATETIME_INVALID<< endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_RENAME:
		cout<<MESSAGE_ERROR_RENAME<< endl;
		//cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_RENAME_NO_NEW_NAME:
		cout<<MESSAGE_ERROR_RENAME_NO_NEW_NAME<< endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_RESCHEDULE:
		cout<<MESSAGE_ERROR_RESCHEDULE<< endl;
		//cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_RELOCATE:
		cout<<MESSAGE_ERROR_RELOCATE<< endl;
		//cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_ERROR:: ERROR_SEARCH_TIME_EMPTY:
		cout<<MESSAGE_ERROR_SEARCH_TIME_EMPTY<<endl;
		break;
 
	}

}

void UI:: success ( int code, HANDLE hConsole){
	
	SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	switch(code){

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_ADD:
		cout<<MESSAGE_SUCCESS_ADD<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_REMOVE:
		cout<<MESSAGE_SUCCESS_REMOVE<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_DISPLAY:
		cout<<MESSAGE_SUCCESS_DISPLAY<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_MARK:
		cout<<MESSAGE_SUCCESS_MARK<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_UNMARK:
		cout<<MESSAGE_SUCCESS_UNMARK<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_SEARCH:
		cout<<MESSAGE_SUCCESS_SEARCH<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_SEARCH_RANGE:
		cout<<MESSAGE_SUCCESS_SEARCH_RANGE<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_SEARCH_EMPTY_SLOTS:
		cout<<MESSAGE_SUCCESS_SEARCH_EMPTY_SLOTS<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_UNDO:
		cout<<MESSAGE_SUCCESS_UNDO<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_REDO:
		cout<<MESSAGE_SUCCESS_REDO<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_HELP:
		cout<<endl<<MESSAGE_SUCCESS_HELP<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_RENAME:
		cout<<MESSAGE_SUCCESS_RENAME<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_RESCHEDULE:
		cout<<MESSAGE_SUCCESS_RESCHEDULE<<endl;
		break;

	case STATUS_CODE_SET_SUCCESS:: SUCCESS_CLEAR:
		cout<<MESSAGE_SUCCESS_CLEAR<<endl;
		break;

	
	}
}

void UI:: warning(int code, HANDLE hConsole ){
		
	SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY);

	switch(code){

	
	case STATUS_CODE_SET_WARNING:: WARNING_DISPLAY_NO_RESULT:
		cout<<MESSAGE_WARNING_DISPLAY_NO_RESULT;
		break;

	case STATUS_CODE_SET_WARNING:: WARNING_MARK_NO_CHANGE:
		cout<<MESSAGE_WARNING_MARK_NO_CHANGE<<endl;
		break;

	case STATUS_CODE_SET_WARNING:: WARNING_SEARCH_NO_RESULT:
		cout<<MESSAGE_WARNING_SEARCH_NO_RESULT<<endl;
		break;

	case STATUS_CODE_SET_WARNING:: WARNING_SEARCH_NO_SLOTS:
		
		cout<<MESSAGE_WARNING_SEARCH_NO_RESULT<<endl;
		break;

	case STATUS_CODE_SET_WARNING:: WARNING_UNDO_NO_COMMAND:
		cout<<MESSAGE_WARNING_UNDO_NO_COMMAND<<endl;
		break;

	case STATUS_CODE_SET_WARNING:: WARNING_REDO_NO_COMMAND:
		cout<<MESSAGE_WARNING_REDO_NO_COMMAND<<endl;
		break;

	case STATUS_CODE_SET_WARNING::WARNING_WRONG_INPUT:
		cout<<MESSAGE_WARNING_WRONG_INPUT<<endl;
		cout<<COMMAND_POSSIBLE_INPUT<<endl;
		cout<<COMMAND_HELP<<endl;
		break;

	case STATUS_CODE_SET_WARNING::WARNING_DISPLAY_TASK:
		cout << MESSAGE_WARNING_DISPLAY_TASK <<endl;
		break;

	case STATUS_CODE_SET_WARNING::WARNING_CLEAR:
		cout << MESSAGE_WARNING_CLEAR << endl;
		break;

	case STATUS_CODE_SET_WARNING::WARNING_RENAME_CLASH:
		cout<<MESSAGE_WARNING_RENAME_CLASH<<endl;
		break;
	
}
	
}
void UI::SetColor(int value){
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),  value);
}

